package cc.example.mybatislike.config;

import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@MapperScan(basePackages = {"com.example.mybatislike.db.hermeslink"},
    sqlSessionFactoryRef = "hermesSqlSessionFactory")
public class HermesLinkConfig {

  @Bean(name = "hermesLinkDataSource")
  @ConfigurationProperties("spring.datasource.hermeslink")
  public DataSource dataSourceHermes() {
    return new HikariDataSource();
  }

  @Bean(name = "hermesSqlSessionFactory")
  public MybatisSqlSessionFactoryBean hermesMybatisSqlSessionFactoryBean(@Qualifier("hermesLinkDataSource") DataSource hermesLinkDataSource) {
    MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean();
    factoryBean.setDataSource(hermesLinkDataSource);
    return factoryBean;
  }




}
